package com.pig4cloud.pigx.strategy.executor.contract.order;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pig4cloud.pigx.common.customize.exception.ApiRequestException;
import com.pig4cloud.pigx.strategy.bo.StrategyTaskContractCacheBO;
import com.pig4cloud.pigx.strategy.bo.StrategyTaskContractCalculateProfitBO;
import com.pig4cloud.pigx.strategy.bo.okx.PlaceOrderBO;
import com.pig4cloud.pigx.strategy.bo.okx.SyncOrderBO;
import com.pig4cloud.pigx.strategy.dto.StrategySyncOrderMsgDTO;
import com.pig4cloud.pigx.strategy.entity.StrategyContract;
import com.pig4cloud.pigx.system.entity.SystemProduct;
import org.springframework.beans.factory.InitializingBean;

import java.math.BigDecimal;
import java.util.List;

/**
 * 策略-合约 订单处理器
 *
 * @since 2022/11/27 19:51
 */
public interface StrategyOrderContractHandler extends InitializingBean {

    /**
     * 根据平台id判断是否支持
     *
     * @param platformId 平台id
     * @return {@link boolean}
     * @since 2022/11/29 17:27
     */
    boolean support(Long platformId);

    /**
     * 查询余额
     *
     * @param userId 用户id
     * @return {@link BigDecimal}
     * @since 2022/11/29 17:44
     */
    BigDecimal accountBalance(Long userId) throws ApiRequestException;

    /**
     * 下单
     *
     * @param boList boList
     * @return {@link List< StrategySyncOrderMsgDTO< PlaceOrderBO>>}
     * @since 2022/11/29 17:44
     */
    List<StrategySyncOrderMsgDTO<PlaceOrderBO>> placeOrder(List<PlaceOrderBO> boList);

    /**
     * 获取产品信息
     *
     * @param productName 产品名称
     * @return {@link JSONObject}
     * @since 2022/11/30 17:12
     */
    JSONObject getProductInfo(String productName) throws ApiRequestException;

    /**
     * 同步订单状态
     *
     * @param bo bo
     * @since 2022/11/29 17:44
     */
    void syncOrder(SyncOrderBO bo) throws ApiRequestException;

    /**
     * 计算收益和收益率数据
     *
     * @param task     任务信息
     * @param strategy 策略信息
     * @param product  产品信息
     * @param price    当前币对价格
     * @return {@link StrategyTaskContractCalculateProfitBO}
     * @since 2022/11/28 20:31
     */
    StrategyTaskContractCalculateProfitBO calculateProfit(StrategyTaskContractCacheBO task,
                                                          StrategyContract strategy,
                                                          SystemProduct product,
                                                          BigDecimal price);

    /**
     * 查询仓位信息
     *
     * @param userId      用户id
     * @param productName 产品名称
     * @return {@link JSONArray}
     * @since 2022/12/8 17:59
     */
    JSONArray positions(Long userId, String productName,String symbolName) throws ApiRequestException;
}
